package com.wanger.swa.domain.myEnum;

import cn.hutool.core.lang.func.Func0;
import cn.hutool.core.lang.func.Func1;
import cn.hutool.core.lang.func.LambdaUtil;
import com.wanger.swc.util.myEnum.BaseEnum;
import com.wanger.swc.util.myEnum.MyEnumUtil;
import com.wanger.swa.domain.po.DataSourcePO;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.Map;

/**
 * @Author: wanger
 * @Date: 2024/9/15 12:52
 * @Description: 数据源
 */
@Getter
@AllArgsConstructor
@SuppressWarnings("unused")
public enum DataSourceEnum implements BaseEnum {
    //数据源类型
    STRUCTURE(DataSourcePO::getType, "structure", "数据结构"),
    INSTANCE(DataSourcePO::getType, "instance", "数据实例"),

    ;

    <E> DataSourceEnum(Func1<E, ?> getFunc, String code, String name) {
        this(LambdaUtil.getFieldName(getFunc), code, name);
    }

    //作用的字段
    private final String field;
    //枚举编码
    private final String value;
    //枚举名称
    private final String label;

    public static final MyEnumUtil<DataSourceEnum> util = MyEnumUtil.create(DataSourceEnum.values());

    public static Map<String, DataSourceEnum> getMapByField(String field) {
        return util.getMapByField(field);
    }

    public static DataSourceEnum getEnumByFieldAndCode(String field, String code) {
        return util.getEnumByFieldAndCode(field, code);
    }

    public static DataSourceEnum getEnumByFieldAndCode(Func0<String> getFunc) {
        return util.getEnumByFieldAndCode(getFunc);
    }

    public static String getEnumName(Func0<String> getFunc) {
        return util.getEnumName(getFunc);
    }

    public static Map<String, Map<String, DataSourceEnum>> getMap() {
        return util.getMap();
    }

    public static Map<String, List<Map<String, String>>> getList() {
        return util.getList();
    }

}
